package org.example.com.zwh.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class RedisService {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public void publishTask(String userId, String productId) {
        String queueKey = "seckill:queue";
        Map<String, String> task = new HashMap<>();
        task.put("userId", userId);
        task.put("productId", productId);


        redisTemplate.opsForList().rightPush(queueKey, task);
    }

    public void deleteTask(String userId, String productId) {
        String queueKey = "seckill:queue:" + productId;
        Map<String, String> task = new HashMap<>();
        task.put("userId", userId);
        task.put("productId", productId);
        redisTemplate.opsForList().remove(queueKey, 0, task);
    }
}
